// stores/global.ts
import { defineStore } from 'pinia'

const ENV_PREFIX = '_'+process.env.NODE_ENV
interface State {
  linkParams: Record<string, any>
}
interface Actions {
  setParams(params: Record<string, any>): void
}

export const useGlobalStore = defineStore('global', {
  state: (): State => ({
     linkParams: {} as Record<string, any>,
  }),
  actions: {
    setParams(params: Record<string, any>) {
      this.linkParams = { ...params }
      console.log('【pinia ----> setParams 方法 -----> linkParams】', { ...this.linkParams })
    },
  },
  persist: {
    key: `global_${ENV_PREFIX}`, // ✅ 加上环境后缀防止串环境
    storage: sessionStorage, // ✅ 改成 sessionStorage（默认是 localStorage）
  } 
})
